//*********************************************************
//
//    Copyright (c) Microsoft. All rights reserved.
//    This code is licensed under the Apache License, Version 2.0.
//    THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
//    ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
//    IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
//    PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using System.Resources;
using System.Globalization;
using System.Windows.Input;

namespace Microsoft.Research.ScientificWorkflow.TridentUtilities
{
    public static class CursorUtilities
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public static Cursor GetCursor(string path)
        {
            Stream cursorStream = LoadResourceStream(Assembly.GetExecutingAssembly(), path);
            return new Cursor(cursorStream);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="assembly"></param>
        /// <param name="resId"></param>
        /// <returns></returns>
        private static Stream LoadResourceStream(Assembly assembly, string resId)
        {
            string basename = System.IO.Path.GetFileNameWithoutExtension(assembly.ManifestModule.Name) + ".g";

            ResourceManager resourceManager = new ResourceManager(basename, assembly);

            // resource names are lower case and contain
            // only forward slashes
            return (resourceManager.GetObject(resId.ToLower(CultureInfo.CurrentCulture).Replace('\\', '/')) as Stream);
        }
    }
}
